package com.view;

import java.awt.Color;

import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.base.standardization;
import com.data.Data;
import com.db.sevent.UserEvent;
import com.db.sevent.WorkUserEvent;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class P2 extends JPanel implements standardization{
	public JTextArea  text01;
	public JLabel lb01;
	public JScrollPane scrollPane,scrollPane02,scrollPane03,scrollPane04,scrollPane05,scrollPane06;
	public JButton bt06,bt07;
	public JList<String> list02,list03,list04,list05,list06;
	public String selectName;
	
	public static P2 instance = new P2(); 
	public JLabel lb1,lb2,lb3,lb4,lb5;
	
	public JList<String> selectList;
	public int selectListIndex;
	
	private P2() {
		init();
		initEvent();
		event();
	}
	@SuppressWarnings("rawtypes")
	public void init() {
		int WIDTH = Data.config.PanelW2;
		int HEIGHT = Data.config.HEIGHT;
		setBounds(Data.config.PanelW1, 0, WIDTH, HEIGHT);
		setBackground(new Color(255, 255,  200));
		setLayout(null);
		
		text01 = new JTextArea();
		list02 = new JList<>();
		list03 = new JList<>();
		list04 = new JList<>();
		list05 = new JList<>();
		list06 = new JList<>();
		
		lb1 = new JLabel("已交：");
		lb2 = new JLabel("通过：");
		lb3 = new JLabel("未通过:999");
		lb4 = new JLabel("跳过：");
		lb5 = new JLabel("未交：");
		lb01 = new JLabel(Data.config.lb01Title);
		bt06 = new JButton(Data.config.bt06Title);
		bt07 = new JButton(Data.config.bt07Title);
		
		scrollPane = new JScrollPane();
		scrollPane02 = new JScrollPane();
		scrollPane03 = new JScrollPane();
		scrollPane04 = new JScrollPane();
		scrollPane05 = new JScrollPane();
		scrollPane06 = new JScrollPane();
		initLayout();
		initOther();
		add(lb01);
		add(scrollPane02);
		add(scrollPane03);
		add(scrollPane04);
		add(scrollPane05);
		add(scrollPane06);
		add(scrollPane);
//		add(bt06);
		add(bt07);
		add(lb1);
		add(lb2);
		add(lb3);
		add(lb4);
		add(lb5);
		
	
	}

	@Override
	public void initLayout() {
		lb1.setBounds(10, 199, 62, 15);
		lb2.setBounds(76, 199, 62, 15);
		lb3.setBounds(145, 199, 70, 15);
		lb4.setBounds(214, 199, 62, 15);
		lb5.setBounds(283, 199, 62, 15);
		lb01.setBounds(10, 147, 308, 15);
		bt06.setBounds(49, 453, 93, 23);
		bt07.setBounds(10, 420, 93, 30);
		scrollPane.setBounds(283, 224, 68, 168);
		scrollPane02.setBounds(7, 224, 62, 168);
		scrollPane03.setBounds(76, 224, 62, 168);
		scrollPane04.setBounds(145, 224, 62, 168);
		scrollPane05.setBounds(214, 224, 62, 168);
		scrollPane06.setBounds(10, 10, 335, 127);
	}
	@Override
	public void initOther() {
		// TODO Auto-generated method stub
		lb01.setFont(new Font("宋体", Font.PLAIN, 16));
		
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		
		scrollPane02.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane02.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		
		scrollPane03.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane03.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		
		scrollPane04.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane04.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		
		scrollPane05.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane05.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

		scrollPane02.setViewportView(list02);
		scrollPane03.setViewportView(list03);
		scrollPane04.setViewportView(list04);
		scrollPane05.setViewportView(list05);
		scrollPane.setViewportView(list06);
		
		text01.setLineWrap(true);
		scrollPane06.setViewportView(text01);
	}
	@Override
	public void initEvent() {
		
		
	}
	@Override
	public void event() {
		// TODO Auto-generated method stub
	
		bt06.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				//代码
			}
		});
		
		bt07.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				//代码

			}
		});
		list02.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
				upSelectList(list02);
				
				
			}
		});
		list03.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
				upSelectList(list03);
			}
		});
		list04.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
				upSelectList(list04);
			}
		});
		list04.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
//				upSelectList(list04);
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				
			}
		});
		list05.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent e) {
				upSelectList(list05);
			}
		});
		list06.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				
			}
		});
		bt07.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new UserEvent().openExplorer();
			}
		});
	}
	
	private void upSelectList(JList<String> com) {
		if(!com.equals(list02)) {
			list02.clearSelection();
		}
		if(!com.equals(list03)) {
			list03.clearSelection();
		}
		if(!com.equals(list04)) {
			list04.clearSelection();
		}
		if(!com.equals(list05)) {
			list05.clearSelection();
		}
		if(!com.equals(list06)) {
			list06.clearSelection();
		}
		P2.instance.selectList = com;
		selectName = (String) com.getSelectedValue();
//		System.out.println(this.selectName);
//		System.out.println(selectName);
		if(selectName==null)return;
		new WorkUserEvent().getUserWork();
	}
}
